// JavaScript Document
ajaxUploadImage = {
	createUploadIframe:function (frameId){		
		var uri = false;
		if(window.ActiveXObject){
			var iframeDom = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
			if(typeof uri== 'boolean'){
				iframeDom.src = 'javascript:false';
			}else if(typeof uri== 'string'){
				iframeDom.src = uri;
			}
			document.body.appendChild(iframeDom);
		}else{
			var iframeDom = document.createElement('iframe');
			iframeDom.id = frameId;
			iframeDom.name = frameId;
			document.body.appendChild(iframeDom);
		}
		iframeDom.style.position = "absolute";
		iframeDom.style.top = '-1000px';
		iframeDom.style.left = '-1000px';
		return iframeDom;
	},
	
	uploadFile : function (varObj){
		var iframeResponseText;
		var frameId = "uploadIframe";
		var iframeUpload = ajaxUploadImage.createUploadIframe(frameId);
		var formUpload = document.getElementById(varObj.formId);
		var uploadCallback = function(){
			//try {
			if(iframeUpload.contentWindow){
				iframeResponseText = iframeUpload.contentWindow.document.body?iframeUpload.contentWindow.document.body.innerHTML:null;
			}else if(iframeUpload.contentDocument){
				iframeResponseText = iframeUpload.contentDocument.document.body?iframeUpload.contentDocument.document.body.innerHTML:null;
			}else{
				iframeResponseText = null;
			}
			if(iframeResponseText != null){
				setTimeout(function(){
									document.body.removeChild(iframeUpload);
							}, 100)
					varObj.success(eval("("+iframeResponseText+")"));
			}else{
				setTimeout(function(){document.body.removeChild(iframeUpload);}, 100);
				document.body.removeChild(iframeUpload);
				varObj.error("上传失败");
			}
			//} //catch(e){alert(e)}
		};
		
		formUpload.action = varObj.formAction;
		if(formUpload.encoding){
			formUpload.encoding = varObj.formEnctype;				
		}else{				
			formUpload.enctype = varObj.formEnctype;
		}			
		formUpload.target = frameId;
		formUpload.submit();
		
		if(window.attachEvent){
            iframeUpload.attachEvent('onload', uploadCallback);
        }
        else{
            iframeUpload.addEventListener('load', uploadCallback, false);
        }
		return false;
	}
}
/*用户通过upload方式上传*/
function uploadImage_bighead(){
		data = ""; 
 		spliter = "-------7d8d733180846" ; 
 		datadata = data + spliter + "\r\n"   
 		datadata = data + "Content-Disposition: form-data; name=\"photofile\"; filename=\"F:\www\images\reg\reg.jpg"+"\r\n";  
 		datadata = data + "Content-Type: image/pjpeg"  
 		text = "My name is Wilson Lin."  
 		postLength = text.length + data.length + 2 + spliter.length + 4   
 		package = data + text + "\r\n" + spliter + "--\r\n" ; 
		if(typeof pageName != "undefined" && pageName != "")
			var url="/ajax/sign.php?"+pageName;
		else
			var url="/ajax/sign.php";
		var par = [];
		var pars="act=getuploadframe";
		par.push(pars);
		var pars="package="+datadata;
		par.push(pars);
		pars = par.join("&");
		new Ajax.Request(url,{method:"post",parameters:pars,onComplete:function(e){
			var temp=eval("("+e.responseText+")");
			if(temp.rtn_code == "nosession"){
				alert("Need login"); 
			}else{
				
			}
		}});
	}